package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author konki
 * @time   2018年6月19日 下午7:03:47
 * @email  konki@qq.com
 * @description 
 */
@Controller
@RequestMapping("permission")
public class PermissionController {
	@Autowired
	IPermissionService service;

	@RequestMapping("")
	public String index(){
		return "permission/list";
	}

	@RequestMapping("list")
	@ResponseBody
	public List<Permission> queryDepts(){
		return service.selectAll();
	}

	//加载权限
	@RequestMapping("reload")
	@ResponseBody
	public JsonResult reload(){
		JsonResult result = new JsonResult();
		try {
			service.reload();
		} catch (Exception e) {
			e.printStackTrace();
			result.markMsg("操作失败");
		}
		return result;
	}
	//回显角色的权限
	@RequestMapping("queryPermissionByRoleId")
	@ResponseBody
	public List<Permission> queryPermissionByRoleId(Long roleId){
		return service.queryPermissionByRoleId(roleId);
	}
}
